{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Thousand Separator"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #string"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #字符串"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: thousandSeparator"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #千位分隔数"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给你一个整数&nbsp;<code>n</code>，请你每隔三位添加点（即 &quot;.&quot; 符号）作为千位分隔符，并将结果以字符串格式返回。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>n = 987\n",
    "<strong>输出：</strong>&quot;987&quot;\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>n = 1234\n",
    "<strong>输出：</strong>&quot;1.234&quot;\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 3：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>n = 123456789\n",
    "<strong>输出：</strong>&quot;123.456.789&quot;\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 4：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>n = 0\n",
    "<strong>输出：</strong>&quot;0&quot;\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>0 &lt;= n &lt; 2^31</code></li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [thousand-separator](https://leetcode.cn/problems/thousand-separator/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [thousand-separator](https://leetcode.cn/problems/thousand-separator/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['987', '1234']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        v = \"\"\n",
    "        i = 1\n",
    "        while n:\n",
    "            # for _ in range(3):\n",
    "            # if n > 0:\n",
    "            v = str(n % 10) + v\n",
    "            n //= 10\n",
    "            # vs.append(v)\n",
    "            if i % 3 == 0:\n",
    "                v = \".\" + v\n",
    "            i += 1\n",
    "        # return \".\".join(vs[::-1]) if len(vs) > 0 else \"0\"\n",
    "        return v.lstrip(\".\") if len(v) > 0 else \"0\"\n",
    "\n",
    "\n",
    "n = 51040\n",
    "res = Solution().thousandSeparator(n)\n",
    "assert res == \"51.040\", res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        s = str(n)\n",
    "        length = len(s)\n",
    "        if length < 4:\n",
    "            return s\n",
    "        count = length // 3\n",
    "        temp = length % 3\n",
    "        ans = \"\"\n",
    "        ans += s[:temp]\n",
    "        for i in range(count):\n",
    "            if ans == \"\":\n",
    "                ans += s[temp + i * 3 : temp + i * 3 + 3]\n",
    "            else:\n",
    "                ans += \".\" + s[temp + i * 3 : temp + i * 3 + 3]\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        n_l = list(str(n))\n",
    "        l = len(n_l)\n",
    "        i = 1\n",
    "        while 3*i < l:\n",
    "            n_l.insert(-3*i-i+1,'.')\n",
    "            i += 1\n",
    "        return ''.join(n_l)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        s = str(n)[::-1]\n",
    "        lst = [s[i: i + 3][::-1] for i in range(0, len(s), 3)]\n",
    "        return \".\".join(lst[::-1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        li = list(str(n))\n",
    "        n = len(li)\n",
    "        for i in range(n-3, 0, -3):\n",
    "            li.insert(i, '.')\n",
    "        return ''.join(li)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        return format(n, ',').replace(',', '.')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        if n < 1000:\n",
    "            return str(n)\n",
    "        yushu = 0\n",
    "        res = ''\n",
    "        while n >= 1000:\n",
    "            tmp = str(n % 1000)\n",
    "            tmp = '0' * (3 - len(tmp)) + tmp\n",
    "            res = '.' + tmp + res\n",
    "            n = n // 1000\n",
    "        return str(n) + res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        n = str(n)\n",
    "        l=len(n)-3\n",
    "        while l > 0:\n",
    "            n= n[:l]+'.'+n[l:]\n",
    "            l-=3\n",
    "        return n\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        n = list(str(n))\n",
    "        if len(n) <= 3:\n",
    "            return \"\".join(n)\n",
    "        index = len(n)-1\n",
    "        for i in range(len(n)-3,0,-3):\n",
    "            n.insert(i,\".\")\n",
    "        return \"\".join(n)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        count = 0\n",
    "        ans = list()\n",
    "        while True:\n",
    "            cur = n % 10\n",
    "            n //= 10\n",
    "            ans.append(str(cur))\n",
    "            count += 1\n",
    "            if count % 3 == 0 and n > 0:\n",
    "                ans.append(\".\")\n",
    "            if n == 0:\n",
    "                break\n",
    "        return \"\".join(ans[::-1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        if n == 0:\n",
    "            return '0'\n",
    "        ans = ''\n",
    "        while n > 0:\n",
    "            if n > 1000:\n",
    "                ans = '.' + '0' * (3-len(str(n%1000)))+ str(n%1000) + ans\n",
    "            else:\n",
    "                ans = str(n % 1000) + ans\n",
    "            n = n//1000\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        n = str(n)\n",
    "        lst = []\n",
    "        for i in range(len(n)-1,-1,-3):\n",
    "            if i-2>=0:\n",
    "                lst.append(n[i-2:i+1])\n",
    "            else:\n",
    "                lst.append(n[:i+1])\n",
    "        return \".\".join(lst[::-1])\n",
    "\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        n = str(n)\n",
    "        c = 0\n",
    "        res = ''\n",
    "        for i in n[::-1]:\n",
    "            if c==3:\n",
    "                res = i+'.'+res\n",
    "                c = 1     \n",
    "            else:\n",
    "                res = i+res\n",
    "                c += 1\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        ans = []\n",
    "        cnt = 0\n",
    "        for i, ch in enumerate(reversed(str(n))):\n",
    "            ans.append(ch)\n",
    "            cnt += 1\n",
    "            if cnt == 3 and i < len(str(n))-1:\n",
    "                ans.append('.')\n",
    "                cnt = 0\n",
    "        return ''.join(ans[::-1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        return format(n,',').replace(',','.')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        num = str(n)\n",
    "        res=\"\"\n",
    "        for i in range(len(num)):\n",
    "            if i>0 and (len(num)-i)%3==0:\n",
    "                res+='.'\n",
    "            res+=num[i]\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        temp=str(n)[::-1]\n",
    "        res=''\n",
    "        for i in range(0,len(temp),3):\n",
    "            res+=temp[i:i+3]+'.'\n",
    "        res=res[::-1]\n",
    "        if res.startswith('.'):\n",
    "            res=res[1:]\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        s = str(n)\n",
    "        ans = \"\"\n",
    "        length = len(s)\n",
    "        for i in range(length):\n",
    "            if i > 0 and (length - i) % 3 == 0:\n",
    "                ans += '.'\n",
    "            ans += s[i]\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        if n == 0:\n",
    "            return '0'\n",
    "        ans = []\n",
    "        i = 0\n",
    "        while n > 0:\n",
    "            a = n % 10\n",
    "            ans.append(str(a))\n",
    "            i += 1\n",
    "            if i % 3 == 0:\n",
    "                ans.append('.')\n",
    "            n //= 10\n",
    "        if ans[-1] == '.':\n",
    "            ans.pop()\n",
    "        return ''.join(ans[::-1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        s = str(n)\n",
    "        lg = len(s)\n",
    "        res = s[:lg%3]\n",
    "        for i in range(lg%3, lg, 3):\n",
    "            res += f'.{s[i:i+3]}'\n",
    "        return res if res[0]!='.' else res[1:]\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "        res = ''\n",
    "        s = str(n)\n",
    "        for i in range(len(s)-3, -1, -3):\n",
    "            #print(i, s[i:i+3])\n",
    "            res = s[i:i+3] + '.' + res\n",
    "        if len(s)%3:\n",
    "            res = s[:len(s)%3]+'.'+res\n",
    "        return res[:-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        l=list(str(n))\n",
    "        i=len(l)-3\n",
    "        while i>0:\n",
    "            l.insert(i,'.')\n",
    "            i-=3\n",
    "        return \"\".join(l)\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        li = list(str(n))\n",
    "        n = len(li)\n",
    "        for i in range(n-1, 0, -1):\n",
    "            if (n-i) % 3 == 0:\n",
    "                li.insert(i, '.')\n",
    "        return ''.join(li)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        if n == 0: return '0'\n",
    "        count = 0\n",
    "        ans = list()\n",
    "        while n != 0:\n",
    "            cur = n % 10\n",
    "            n //= 10\n",
    "            ans.append(str(cur))\n",
    "            count += 1\n",
    "            if count % 3 == 0 and n > 0:\n",
    "                ans.append(\".\")\n",
    "        return \"\".join(ans[::-1])\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        str_n=[]\n",
    "        while n > 1000:\n",
    "            str_n.insert(0,'{:03d}'.format(n%1000))\n",
    "            n//=1000\n",
    "        str_n.insert(0,'{}'.format(n%1000))\n",
    "        return '.'.join(str_n) if str_n else \"0\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        n = str(n)[::-1]\n",
    "        new_n = ''\n",
    "        for i,num in enumerate(n):\n",
    "            new_n+=num\n",
    "            if (i+1)%3==0 and i+1 !=len(n):\n",
    "                new_n+='.'\n",
    "        return new_n[::-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        n = list(str(n))\n",
    "        if len(n) <= 3:\n",
    "            return \"\".join(n)\n",
    "        for i in range(len(n), 0, -3):\n",
    "            n.insert(i, '.')\n",
    "        return \"\".join(n)[:-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        count = 0\n",
    "        ans = list()\n",
    "        while True:\n",
    "            cur = n % 10\n",
    "            n //= 10\n",
    "            ans.append(str(cur))\n",
    "            count += 1\n",
    "            if count % 3 == 0 and n > 0:\n",
    "                ans.append(\".\")\n",
    "            if n == 0:\n",
    "                break\n",
    "        return \"\".join(ans[::-1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        ans = []\n",
    "        n = list(str(n))\n",
    "        if len(n) <= 3:\n",
    "            return ''.join(n)\n",
    "        else:\n",
    "            for i in range(len(n)):\n",
    "                ans.append(n[i])\n",
    "                if len(n[i+1:]) % 3 == 0 and len(n[i+1:]) != 0:\n",
    "                    ans.append('.')\n",
    "            return ''.join(ans)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        ans = str(n)\n",
    "        for i in range(len(ans) - 4, -1, -3):\n",
    "            ans = ans[:i + 1] + \".\" + ans[i + 1:]\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        s = str(n)\n",
    "        j = 0\n",
    "        ans = list(s)\n",
    "\n",
    "        for i in range(len(s) - 1, -1, -1):\n",
    "            j += 1\n",
    "            if j % 3 == 0 and i != 0:\n",
    "                ans.insert(i, \".\")\n",
    "        return \"\".join(ans)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        s =str(n)\n",
    "        res = \"\"\n",
    "        for i,ch in enumerate(s[::-1]):\n",
    "            res += ch\n",
    "            if i % 3 == 2 and i != len(s)-1:\n",
    "                res += \".\"\n",
    "        return res[::-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        n=str(n)\n",
    "        ans=''\n",
    "        x=0\n",
    "        for i in n[::-1]:\n",
    "            ans=i+ans\n",
    "            x+=1\n",
    "            if x==3:\n",
    "                ans='.'+ans\n",
    "                x=0\n",
    "        return ans.strip('.')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        ans = []\n",
    "        s = \"\"\n",
    "\n",
    "        n = str(n)\n",
    "\n",
    "        c = len(n)\n",
    "\n",
    "        i = c-1\n",
    "        temp = \"\"\n",
    "        while i >=0:\n",
    "            if len(temp) == 3:\n",
    "                ans.append(temp)\n",
    "                temp = \"\"\n",
    "            temp = n[i] + temp\n",
    "            i-=1\n",
    "        ans.append(temp)\n",
    "        ans = ans[::-1]\n",
    "        for i,v in enumerate(ans):\n",
    "            if len(ans) == 1 and i == 0:\n",
    "                s+=v\n",
    "                break\n",
    "            if i == len(ans) -1:\n",
    "                s+=v\n",
    "                break\n",
    "            s+=v+'.'\n",
    "        \n",
    "\n",
    "        return s\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        sn = str(n)[::-1]\n",
    "        \n",
    "        res = ''\n",
    "        for i in range(len(sn)):\n",
    "            res = sn[i] + res\n",
    "            if i + 1 != len(sn) and (i + 1) % 3 == 0:\n",
    "                res = '.' + res\n",
    "                \n",
    "        return res   \n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        if n == 0: return \"0\"\n",
    "        count = 0\n",
    "        res = []\n",
    "        while n > 0:\n",
    "            res.append(str(n % 10))\n",
    "            n //= 10\n",
    "            count += 1\n",
    "            if n > 0 and count == 3:\n",
    "                res.append(\".\")\n",
    "                count = 0\n",
    "        \n",
    "        return \"\".join(res[::-1])\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "        # count = 0\n",
    "        # res = []\n",
    "        # if n == 0: return \"0\"\n",
    "        # while n > 0:\n",
    "        #     cur = n % 10\n",
    "        #     n //= 10\n",
    "        #     res.append(str(cur))\n",
    "        #     count += 1\n",
    "        #     if count == 3 and n > 0:\n",
    "        #         res.append(\".\")\n",
    "        #         count = 0\n",
    "            \n",
    "            \n",
    "        \n",
    "        # return \"\".join(res[::-1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        res = list(str(n))\n",
    "        i = len(res)-3\n",
    "        while i>0:\n",
    "            res.insert(i, '.')\n",
    "            i-=3\n",
    "        return ''.join(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        ans = str(n)\n",
    "        for i in range(len(ans) - 4, -1, -3):\n",
    "            ans = ans[:i + 1] + \".\" + ans[i + 1:]\n",
    "        return ans\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        if n<1000:\n",
    "            return str(n)\n",
    "        mid = []\n",
    "        while n>0:\n",
    "            temp = str(n%1000)\n",
    "            n //= 1000\n",
    "            while len(temp)<3 and n>0:\n",
    "                temp = '0'+temp\n",
    "            \n",
    "            \n",
    "            mid.append(temp)\n",
    "        return '.'.join(mid[::-1])\n",
    "\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "\n",
    "        res = list(str(n))\n",
    "        nos = len(list(str(n)))//3 if len(list(str(n)))%3!=0 else len(list(str(n)))//3-1\n",
    "\n",
    "        indexs = [ 3+3*i if len(list(str(n)))%3 ==0 else len(list(str(n)))%3+3*i \n",
    "                  for i in range(nos) ]\n",
    "        \n",
    "        for i, index in zip(range(len(indexs)),indexs):\n",
    "            res.insert(index+i,\".\")\n",
    "            \n",
    "        return ''.join(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        ans = str(n)\n",
    "        for i in range(len(ans) - 4, -1, -3):\n",
    "            ans = ans[:i + 1] + \".\" + ans[i + 1:]\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        res = \"\"\n",
    "        n = str(n)\n",
    "        cnt = 0\n",
    "        for i in range(len(n)-1, -1, -1):\n",
    "            res += n[i]\n",
    "            cnt += 1\n",
    "            if cnt == 3:\n",
    "                res += '.'\n",
    "                cnt = 0\n",
    "        print(res)\n",
    "        return res[::-1] if res[-1] !='.' else res[-2::-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        nss = \".\".join([str(n)[::-1][i:i+3] for i in range(0, len(str(n)), 3)])\n",
    "        return nss[::-1]\n",
    "print(Solution().thousandSeparator(0))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        nums = list(str(n)[::-1])\n",
    "        res = []\n",
    "        for i in range(len(nums)):\n",
    "            if (i+1)%3==0 and i!=len(nums)-1:\n",
    "                res.append(nums[i])\n",
    "                res.append('.')\n",
    "            else:\n",
    "                res.append(nums[i])\n",
    "        return \"\".join(res[::-1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        count = 0\n",
    "        ans = list()\n",
    "        while True:\n",
    "            cur = n % 10\n",
    "            n //= 10\n",
    "            ans.append(str(cur))\n",
    "            count += 1\n",
    "            if count % 3 == 0 and n > 0:\n",
    "                ans.append(\".\")\n",
    "            if n == 0:\n",
    "                break\n",
    "        return \"\".join(ans[::-1])\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        count = 0\n",
    "        res = []\n",
    "        if n == 0: return \"0\"\n",
    "        while n > 0:\n",
    "            cur = n % 10\n",
    "            n //= 10\n",
    "            res.append(str(cur))\n",
    "            count += 1\n",
    "            if count == 3 and n > 0:\n",
    "                res.append(\".\")\n",
    "                count = 0\n",
    "            \n",
    "        \n",
    "        return \"\".join(res[::-1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        li = list(str(n))\n",
    "        n = len(li)\n",
    "        for i in range(n-3, 0, -3):\n",
    "            li.insert(i, '.')\n",
    "        return ''.join(li)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        s=''\n",
    "        i=0 \n",
    "        if n==0:\n",
    "            return '0'\n",
    "        while n:\n",
    "            s=str(n%10)+s\n",
    "            i+=1\n",
    "            if i%3==0:\n",
    "                s='.'+s\n",
    "            n=n//10\n",
    "        if s[0]=='.':\n",
    "            s=s[1:]\n",
    "        return s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        # return '.'.join([str(n)[max(0,len(str(n))-i-3):len(str(n))-i] for i in range(0,len(str(n)),3)][::-1])\n",
    "        s=str(n)\n",
    "        ans=''\n",
    "        for i in range(len(s)-1,-1,-3):\n",
    "            ans=s[max(0,i-2):i+1]+'.'+ans\n",
    "        return ans[:-1]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        state = str(n)\n",
    "        res = ''\n",
    "        i = len(state)\n",
    "        while i > 0:\n",
    "            res = '.' + state[max(0,i-3):i] + res\n",
    "            i -= 3\n",
    "            #print(res)\n",
    "\n",
    "        return res[1:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "# Review!! Implementation details.\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        if n < 1000: return str(n)\n",
    "        result = str(n % 1000).zfill(3)\n",
    "        n //= 1000\n",
    "        while n:\n",
    "            if n >= 1000:\n",
    "                result = str(n % 1000).zfill(3) + \".\" + result\n",
    "            else:\n",
    "                result = str(n % 1000) + \".\" + result\n",
    "            n //= 1000\n",
    "        return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        str_n=str(n)\n",
    "        for i in range(len(str_n)-4,-1,-3):\n",
    "            str_n=str_n[:i+1]+'.'+str_n[i+1:]\n",
    "        return str_n\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        cnt = 0\n",
    "        ans = []\n",
    "        while True:\n",
    "            cur = n % 10\n",
    "            n //= 10\n",
    "            ans.append(str(cur))\n",
    "            cnt += 1\n",
    "            if cnt % 3 == 0 and n > 0:\n",
    "                ans.append('.')\n",
    "            if n == 0:\n",
    "                break\n",
    "        return ''.join(ans[::-1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        if n == 0: return \"0\"\n",
    "        res = \"\"\n",
    "        while n:\n",
    "            res = \".\" + f\"{n % 1000:03d}\"  + res if n > 1000 else str(n % 1000) + res\n",
    "            n //= 1000\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        n=str(n)\n",
    "        for i in range(len(n)-3,0,-3):\n",
    "            n=n[:i]+'.'+n[i:]\n",
    "        return n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        n = str(n)\n",
    "        if len(n) <= 3:\n",
    "            return n\n",
    "        n = list(n)\n",
    "        for i in range(len(n), 0, -3):\n",
    "            n.insert(i, '.')\n",
    "        return \"\".join(n)[:-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        if n == 0:\n",
    "            return '0'\n",
    "        result = ''\n",
    "        a, b = n % 10, n // 10\n",
    "        cnt = 0\n",
    "        while True:\n",
    "            result = str(a) + result\n",
    "            cnt += 1\n",
    "\n",
    "            if b == 0:\n",
    "                break\n",
    "            if cnt % 3 == 0:\n",
    "                result = '.' + result\n",
    "            a, b = b % 10, b // 10\n",
    "        return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        res = ''\n",
    "        s = str(n)\n",
    "        for i in range(len(s)-3, -1, -3):\n",
    "            #print(i, s[i:i+3])\n",
    "            res = s[i:i+3] + '.' + res\n",
    "        if len(s)%3:\n",
    "            res = s[:len(s)%3]+'.'+res\n",
    "        return res[:-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "        \n",
    "        res = ''\n",
    "        s = str(n)\n",
    "        for i in range(len(s)-3, -1, -3):\n",
    "            #print(i, s[i:i+3])\n",
    "            res = s[i:i+3] + '.' + res\n",
    "        if len(s)%3:\n",
    "            res = s[:len(s)%3]+'.'+res\n",
    "        return res[:-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        list=[]\n",
    "        s=''\n",
    "        for i in str(n):\n",
    "            list.append(i)\n",
    "        for i in range(-1,0-len(str(n))-1,-1):\n",
    "            if (0-i)%3==1 and i<=-4:\n",
    "                print(i)\n",
    "                list[i]=list[i]+'.'\n",
    "        for i in list:\n",
    "            s+=i\n",
    "        return(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        n = str(n)[::-1]\n",
    "        new_n = ''\n",
    "        for i,num in enumerate(n):\n",
    "            new_n+=num\n",
    "            if (i+1)%3==0 and (i+1)!= len(n):\n",
    "                new_n+='.'\n",
    "        return new_n[::-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        st=str(n)\n",
    "        print(st)\n",
    "        n=len(st)\n",
    "        ans=\"\"\n",
    "        if n<=3:\n",
    "            return st\n",
    "        s=st[::-1]\n",
    "        for i in range(n):\n",
    "            ans+=s[i]\n",
    "            if i %3==2 and i!=n-1:\n",
    "                ans+=\".\"\n",
    "        print(ans)\n",
    "        return ans[::-1]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "from collections import deque\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        ns = str(n)\n",
    "        res = deque()\n",
    "\n",
    "        r = len(ns) - 1\n",
    "        while r >= 0:\n",
    "            l = r - 2\n",
    "            if l <= 0:\n",
    "                l = 0\n",
    "            print(f\"ns[{l},{r+1}] = {ns[l:r+1]}\")\n",
    "            res.appendleft(ns[l:r+1])\n",
    "\n",
    "            r = l - 1\n",
    "        return '.'.join(list(res))\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        sn = str(n)[::-1]\n",
    "        \n",
    "        res = ''\n",
    "        for i in range(len(sn)):\n",
    "            res = sn[i] + res\n",
    "            if i + 1 != len(sn) and (i + 1) % 3 == 0:\n",
    "                res = '.' + res\n",
    "                \n",
    "        return res   \n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        \n",
    "        n_str = str(n)\n",
    "        tmp = deque()\n",
    "        for i in range(len(n_str)):\n",
    "            if i != 0 and i % 3 == 0:\n",
    "                tmp.appendleft('.')\n",
    "            tmp.appendleft(n_str[len(n_str) - 1 - i])\n",
    "        \n",
    "        return ''.join(tmp)\n",
    "\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        count = 0\n",
    "        ans = list()\n",
    "        while True:\n",
    "            cur = n % 10\n",
    "            n //= 10\n",
    "            ans.append(str(cur))\n",
    "            count += 1\n",
    "            if count % 3 == 0 and n > 0:\n",
    "                ans.append('.')\n",
    "            if n == 0:\n",
    "                break\n",
    "        return ''.join(ans[::-1])                                "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        ns = str(n)[::-1]\n",
    "        ans = '.'.join([ns[i:i+3] for i in range(0,len(ns),3)])\n",
    "        return ans[::-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) : \n",
    "        list_n = list(str(n))\n",
    "        length = len(list_n)\n",
    "        if length <= 3:\n",
    "            return str(n)\n",
    "        else:\n",
    "            j = 0\n",
    "            for i in range(-3,length*-1,-3):\n",
    "                list_n.insert(i+j,\".\")\n",
    "                j -=1\n",
    "            return \"\".join(list_n)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        ans = str(n)\n",
    "        for i in range(len(ans) - 4, -1, -3):\n",
    "            ans = ans[:i + 1] + '.' + ans[i + 1:]\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        ln = len(str(n))\n",
    "        if ln <= 3:\n",
    "            return str(n)\n",
    "        k = ln % 3\n",
    "        rn = str(n)[:k]\n",
    "        for i in range(k, ln, 3):\n",
    "            rn += \".\"\n",
    "            rn += str(n)[i:i + 3]\n",
    "        return rn if rn[0] != \".\" else rn[1:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        if n <= 999:\n",
    "            return str(n)\n",
    "        else:\n",
    "            m = []\n",
    "            n = list(str(n))\n",
    "            for i in range(len(n)//3):\n",
    "                m.insert(0, n.pop(-1))\n",
    "                m.insert(0, n.pop(-1))\n",
    "                m.insert(0, n.pop(-1))\n",
    "                if n:\n",
    "                    m.insert(0, '.')\n",
    "            if n:\n",
    "                m.insert(0, n.pop(-1))\n",
    "            if n:\n",
    "                m.insert(0, n.pop(-1))\n",
    "            if n:\n",
    "                m.insert(0, n.pop(-1))\n",
    "\n",
    "            # for i in range(len(n)-1):\n",
    "\n",
    "            m = ''.join(str(x) for x in m)\n",
    "            return m\n",
    "\n",
    "                            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        # str_n=[]\n",
    "        str_n=''\n",
    "        while n > 1000:\n",
    "            # str_n.insert(0,'{:03d}'.format(n%1000))\n",
    "            str_n=\".{:03d}\".format(n%1000)+str_n\n",
    "            n//=1000\n",
    "        # str_n.insert(0,'{}'.format(n%1000))\n",
    "        str_n=\"{}{}\".format(n,str_n)\n",
    "        # return '.'.join(str_n) if str_n else \"0\"\n",
    "        return str_n\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        ans = str(n)\n",
    "        for i in range(len(ans) - 4, -1, -3):\n",
    "            ans = ans[:i + 1] + \".\" + ans[i + 1:]\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        s = str(n)\n",
    "        j = 0\n",
    "        ans = list(s)\n",
    "\n",
    "        for i in range(len(s) - 1, -1, -1):\n",
    "            j += 1\n",
    "            if j % 3 == 0 and i != 0:\n",
    "                ans.insert(i, \".\")\n",
    "        return \"\".join(ans)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        count = 0\n",
    "        res = []\n",
    "        if n == 0: return \"0\"\n",
    "        while n > 0:\n",
    "            res.append(str(n % 10))\n",
    "            n //= 10\n",
    "            count += 1\n",
    "            if n > 0 and count == 3:\n",
    "                res.append(\".\")\n",
    "                count = 0\n",
    "        \n",
    "        return \"\".join(res[::-1])\n",
    "\n",
    "\n",
    "        # count = 0\n",
    "        # res = []\n",
    "        # if n == 0: return \"0\"\n",
    "        # while n > 0:\n",
    "        #     cur = n % 10\n",
    "        #     n //= 10\n",
    "        #     res.append(str(cur))\n",
    "        #     count += 1\n",
    "        #     if count == 3 and n > 0:\n",
    "        #         res.append(\".\")\n",
    "        #         count = 0\n",
    "            \n",
    "            \n",
    "        \n",
    "        # return \"\".join(res[::-1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        ans = str(n)\n",
    "        for i in range(len(ans) - 4, -1, -3):\n",
    "            ans = ans[:i + 1] + \".\" + ans[i + 1:]\n",
    "        return ans\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        res = \"\"\n",
    "        l = len(str(n))\n",
    "        for i,s in enumerate(reversed(str(n))):\n",
    "            res = res + s\n",
    "            if i % 3 == 2 and i != l-1:\n",
    "                res = res + \".\"\n",
    "        return res[::-1]\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        if n == 0: return \"0\"\n",
    "        res = []\n",
    "        count = 0\n",
    "        while n:\n",
    "            res.append(str(n % 10))\n",
    "            n //= 10\n",
    "            count += 1\n",
    "            if n > 0 and count == 3:\n",
    "                res.append(\".\")\n",
    "                count = 0\n",
    "        \n",
    "        return \"\".join(res[::-1])\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "        # count = 0\n",
    "        # res = []\n",
    "        # if n == 0: return \"0\"\n",
    "        # while n > 0:\n",
    "        #     cur = n % 10\n",
    "        #     n //= 10\n",
    "        #     res.append(str(cur))\n",
    "        #     count += 1\n",
    "        #     if count == 3 and n > 0:\n",
    "        #         res.append(\".\")\n",
    "        #         count = 0\n",
    "            \n",
    "            \n",
    "        \n",
    "        # return \"\".join(res[::-1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        ## 法一： \n",
    "        # res = str(n)\n",
    "        # length = len(res)\n",
    "\n",
    "        # if length <= 3:\n",
    "        #     return res\n",
    "\n",
    "        # nList = list(res)\n",
    "        # resList = []\n",
    "\n",
    "        # for i in range(1,length+1):\n",
    "        #     resList.insert(0,nList[-i])\n",
    "        #     if -i % 3 == 0 and i < length: \n",
    "        #         resList.insert(0,'.')\n",
    "        \n",
    "        # return \"\".join(resList)\n",
    "\n",
    "        ## 法二： \n",
    "        if n < 1000:\n",
    "            return str(n)\n",
    "\n",
    "        res = []\n",
    "        while n/1000 > 0:\n",
    "            cur = n % 1000\n",
    "            n = n // 1000\n",
    "            if cur<100 and n/1000 > 0:\n",
    "                res.append('0' + str(cur))\n",
    "            else:\n",
    "                res.append(str(cur))\n",
    "        \n",
    "        return \".\".join(res[::-1])\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        a=str(n).split('.')\n",
    "        s=str(a[0])\n",
    "        k=int(len(s)%3)\n",
    "        r=s[0:k]\n",
    "        \n",
    "        while(k<len(s)-3):\n",
    "            k+=3\n",
    "            r+='.'+s[k-3:k]\n",
    "            \n",
    "        if(k!=(len(s)-1)):\n",
    "            r+='.'+s[k:]\n",
    "        if(r[0]=='.'):\n",
    "            r=r[1:]\n",
    "        if(r[-1]=='.'):\n",
    "            r=r[:-1]\n",
    "        return(r)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def thousandSeparator(self, n: int) -> str:\n",
    "        \n",
    "        n_str = str(n)\n",
    "        tmp = deque()\n",
    "        for i in range(len(n_str)):\n",
    "            if i != 0 and i % 3 == 0:\n",
    "                tmp.appendleft('.')\n",
    "            tmp.appendleft(n_str[len(n_str) - 1 - i])\n",
    "        \n",
    "        return ''.join(tmp)\n",
    "\n",
    "\n",
    "\n",
    "\n"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
